//
//  GoodsDeatilTableViewCell.m
//  Youhuiju
//
//  Created by 余尚飞 on 16/8/2.
//  Copyright © 2016年 yutenys. All rights reserved.
//

#import "GoodsDeatilTableViewCell.h"

@interface GoodsDeatilTableViewCell ()
@property (weak, nonatomic) IBOutlet UILabel *saleLabel;//折扣

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;//名称
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;//价格
@property (weak, nonatomic) IBOutlet UILabel *originalCostLabel;//原价
@property (weak, nonatomic) IBOutlet UILabel *goodsdetailLabel;//收藏，销量，运费等


//适配
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *adImgHeight;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleLabelTrailing;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *priceLabelTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *pricelLabelLeading;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *saleLabelTop;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodsdetailLabelLeading;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *goodsdetailTrailing;

@end


@implementation GoodsDeatilTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.saleLabel.layer.cornerRadius = 4 * FitH;
    self.adImgHeight.constant = 45 * FitH;
    
    self.titleLabelTop.constant = 19 * FitH;
    self.titleLabelLeading.constant = 30 * FitW;
    self.titleLabelTrailing.constant = 30 * FitW;
    
    self.priceLabelTop.constant = 20 * FitH;
    self.pricelLabelLeading.constant = 103 * FitW;
    
    self.saleLabelTop.constant = 20 * FitH;
    
    self.goodsdetailTrailing.constant = 20 * FitW;
    self.goodsdetailLabelLeading.constant = 20 * FitW;
    
    self.saleLabel.layer.cornerRadius = 3 * FitH;
    self.saleLabel.layer.borderWidth = 1.0f * FitH;
    self.saleLabel.layer.borderColor = [UIColor colorWithHexString:@"ff5f7b"].CGColor;
    
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:@"¥ 180"];
    
    [attributedString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, 5)];
    
    self.originalCostLabel.attributedText = attributedString;
    
    
    self.saleLabel.hidden = YES;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)setModel:(GoodModel *)model
{
    if (_model != model)
    {
        _model = model;
        
        NSString *price = [NSString stringWithFormat:@"¥ %@",_model.good_price];
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:price];
        NSInteger a = price.length;
        
        [attributedString addAttribute:NSStrikethroughStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, a)];
        self.originalCostLabel.attributedText = attributedString;
        
        self.titleLabel.text = _model.good_name;
        self.priceLabel.text = [NSString stringWithFormat:@"¥ %@",_model.good_price_onSale];
        self.saleLabel.text = [NSString stringWithFormat:@"%@ 折",_model.good_disount];
        self.goodsdetailLabel.text = [NSString stringWithFormat:@"收藏%@件  销量%@件",_model.good_collectCount,_model.good_saleCount];
        DLog(@"%@",_model);
        
        
    }
}

@end
